package ph.com.gs3.formalistics.presenter;

import java.util.List;

import ph.com.gs3.formalistics.R;
import ph.com.gs3.formalistics.global.utilities.logging.FLLogger;
import ph.com.gs3.formalistics.model.dao.SupportDAO;
import ph.com.gs3.formalistics.presenter.fragments.views.SupportViewFragment;
import ph.com.gs3.formalistics.presenter.fragments.views.SupportViewFragment.SupportViewActionListener;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class SupportActivity extends Activity implements SupportViewActionListener {

	public static final String TAG = SupportActivity.class.getSimpleName();

	public static final String EXTRA_CURRENT_USER = "current_user";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_support);

		if (savedInstanceState == null) {
			getFragmentManager().beginTransaction().add(R.id.container, new SupportViewFragment())
			        .commit();
		}
	}

	@Override
	public void onReportIssues() {

		SupportDAO dao = new SupportDAO(this);
		List<String> logFileNames = dao.getLogFileNames();

		for (String logFileName : logFileNames) {

			if (logFileName.contains("error")) {
				FLLogger.e(TAG, dao.getLogContents(logFileName));
			} else if (logFileName.contains("warning")) {
				FLLogger.w(TAG, dao.getLogContents(logFileName));
			}

		}

		Toast.makeText(
		        this,
		        "Your report is now being sent, you may continue working with formalistics while we do so.",
		        Toast.LENGTH_LONG).show();
		finish();

	}
}
